# -*- coding: utf-8 -*-
# @Author : zhaochen
# @Date   : 2019/2/14
# @File   : R24_IC_InquiriesCntCheck.py
# @E-mail : zhaochen@bbdservice.com

'''eof
name:申请人近1个月内贷款、信用卡审批查询机构数校验
code:R24_IC_InquiriesCntCheck
tableName:
columnName:
groups:个人征信校验
dependencies:IC_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import datetime
reload(sys)
sys.setdefaultencoding('utf-8')

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']


def getTable(table_Name):
    try:
        data = IC_DSJ['data'].get(table_Name)
        if data in null_type_list:
            return None
        else:
            # 存在1条为空的数据[{}]
            if isinstance(data, list) and len(data) == 1 and data[0]['reportNo'] in null_type_list:
                return [{}]
            # 存在空list []
            elif isinstance(data, list) and len(data) == 0:
                return None
            else:
                return data
    except:
        return None

def isfloat(x):

    try:
        if isinstance(float(x), float) and float(x)>=0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def R24_IC_InquiriesCntCheck():
    ICRRecordSummary002 = getTable('ICRRecordSummary002')
    if ICRRecordSummary002 is None:
        return u'缺失值'
    elif ICRRecordSummary002 == [{}]:
        return 0
    else:
        orgSum1 = ICRRecordSummary002[0].get('orgSum1')
        orgSum2 = ICRRecordSummary002[0].get('orgSum2')

        if not isfloat(orgSum1) and not isfloat(orgSum2):
            return u'缺失值'
        elif not isfloat(orgSum1) and isfloat(orgSum2):
            return float(orgSum2)
        elif isfloat(orgSum1) and not isfloat(orgSum2):
            return float(orgSum1)
        else:
            return float(orgSum1) + float(orgSum2)

result = R24_IC_InquiriesCntCheck()
